/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelryweb.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author Kateryna_Reznik
 */
@Entity 
@NamedQueries({
   @NamedQuery ( name = "Client.findById",
        query="SELECT c.clientId, c.user, c.reputation "
        + "FROM Client c "
        + "WHERE c.clientId = :clientId"),
   @NamedQuery ( name = "Client.findByReputation",
        query="SELECT c.clientId, c.user, c.reputation "
        + "FROM Client c "
        + "WHERE c.reputation >= :clientReputation"),
   @NamedQuery ( name = "Client.findByUserId",
        query="SELECT c.clientId, c.user, c.reputation "
        + "FROM Client c "
        + "WHERE c.user = :user")
})
@Table( name = "clients" )
public class Client implements Serializable{
    @Id 
    @Column ( name = "client_id" )
    @GeneratedValue ( strategy = GenerationType.TABLE)
    private int clientId;
    @OneToOne
    @JoinColumn (name = "user_id")
    private User user;
    private int reputation;

    public Client() {
    }

    public Client(User user, int reputation) {
        this.reputation = reputation;
        this.user = user;
    }

    public Client(int clientId, User user, int reputation) {
        this.clientId = clientId;
        this.user = user;
        this.reputation = reputation;
    }

    public int getClientId() {
        return clientId;
    }

    public int getReputation() {
        return reputation;
    }

    public void setReputation(int reputation) {
        this.reputation = reputation;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    
    @Override
    public String toString() {
        return "Client{" + "clientId=" + clientId + ", reputation=" + 
                reputation + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.user != null ? this.user.hashCode() : 0);
        hash = 47 * hash + this.reputation;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Client other = (Client) obj;
        if (this.user != other.user && (this.user == null || 
                !this.user.equals(other.user))) {
            return false;
        }
        if (this.reputation != other.reputation) {
            return false;
        }
        return true;
    }
    
    
}
